package com.itheima.googleplay9.holder;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.itheima.googleplay9.R;
import com.itheima.googleplay9.api.Url;
import com.itheima.googleplay9.bean.Category;
import com.itheima.googleplay9.bean.CategoryInfo;
import com.itheima.googleplay9.global.GooglePlayApp;
import com.itheima.googleplay9.global.ImageLoaderOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import butterknife.Bind;

/**
 * Created by lxj on 2016/5/25.
 */
public class CategoryInfoHolder extends BaseHolder {
    @Bind(R.id.iv_image1)
    ImageView ivImage1;
    @Bind(R.id.tv_name1)
    TextView tvName1;
    @Bind(R.id.iv_image2)
    ImageView ivImage2;
    @Bind(R.id.tv_name2)
    TextView tvName2;
    @Bind(R.id.iv_image3)
    ImageView ivImage3;
    @Bind(R.id.tv_name3)
    TextView tvName3;
    @Bind(R.id.ll_info2)
    LinearLayout ll_info2;
    @Bind(R.id.ll_info3)
    LinearLayout ll_info3;

    @Override
    protected View initHolderView() {
        return View.inflate(GooglePlayApp.context, R.layout.adapter_info, null);
    }

    @Override
    public void bindData(Object data) {
        CategoryInfo info = (CategoryInfo) data;

        //显示第一个块的数据
        tvName1.setText(info.getName1());
        ImageLoader.getInstance().displayImage(Url.IMAGE_PREFIX+info.getUrl1(),ivImage1
        , ImageLoaderOptions.round_options);

        //显示第2个和第3个
        //由于第2个和第3个数据可能木哟，那么需要判断
        if(!TextUtils.isEmpty(info.getName2())){
            //由于是复用的，所以当需要显示的时候要设置为可见
            ll_info2.setVisibility(View.VISIBLE);
            tvName2.setText(info.getName2());
            ImageLoader.getInstance().displayImage(Url.IMAGE_PREFIX+info.getUrl2(),ivImage2
                    , ImageLoaderOptions.round_options);
        }else {
            //没有则隐藏
            ll_info2.setVisibility(View.INVISIBLE);
        }
        //显示第3个也需要进行判断
        if(!TextUtils.isEmpty(info.getName3())){
            //由于是复用的，所以当需要显示的时候要设置为可见
            ll_info3.setVisibility(View.VISIBLE);

            tvName3.setText(info.getName3());
            ImageLoader.getInstance().displayImage(Url.IMAGE_PREFIX+info.getUrl3(),ivImage3
                    , ImageLoaderOptions.round_options);
        }else {
            //没有则隐藏
            ll_info3.setVisibility(View.INVISIBLE);
        }
    }
}
